//
//  XMAddressTableViewCell.m
//  XunMi
//
//  Created by MacBook on 2024/3/5.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMAddressTableViewCell.h"
#import "XMAddressModel.h"

@interface XMAddressTableViewCell ()
@property (weak, nonatomic) IBOutlet UIView *bgV;
@property (weak, nonatomic) IBOutlet UILabel *nameLa;
@property (weak, nonatomic) IBOutlet UILabel *phoneLa;
@property (weak, nonatomic) IBOutlet UILabel *defLa;
@property (weak, nonatomic) IBOutlet UILabel *contentLa;
@property (weak, nonatomic) IBOutlet UIButton *defBtn;
@property (weak, nonatomic) IBOutlet UIButton *delBtn;
@property (weak, nonatomic) IBOutlet UIView *bottomV;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *laBottomSpace;

@end

@implementation XMAddressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    kCornerRadius(_bgV, 10, 0, UIColor.clearColor);
    kCornerRadius(_defLa, 4, 1, kAppMainColor);
    [self.defBtn setImagePosition:XMImagePositionLeft spacing:6];
    [self.delBtn setImagePosition:XMImagePositionLeft spacing:6];
}

- (void)setModel:(XMAddressModel *)model {
    _model = model;
    self.nameLa.text = model.recipient;
    self.phoneLa.text = model.mobile;
    self.defLa.hidden = !model.is_default;
    self.contentLa.text = kStringFormat(@"%@ %@", model.region, model.detail_address);
    self.defBtn.selected = model.is_default;
    self.bottomV.hidden = !model.isEdit;
    self.laBottomSpace.constant = model.isEdit ? 53 : 12;
}

- (IBAction)editAct:(UIButton *)sender {
    if (self.detailBlock) {
        self.detailBlock(self.model);
    }
}

- (IBAction)defAct:(UIButton *)sender {
    if (self.defBlock) {
        self.defBlock(self.model);
    }
}

- (IBAction)delAct:(UIButton *)sender {
    if (self.deleteBlock) {
        self.deleteBlock(self.model);
    }
}

@end
